import axios from "axios";
function getHeaders() {
  let token = sessionStorage.getItem("token");
  // let modifyId = sessionStorage.getItem("modifyId");
  let headers = {};
  if (token) {
    headers = {
      "Content-Type": "application/json;charset=utf-8",
      VueType: "vue",
      Authorization: token
    };
  } else {
    headers = {
      "Content-Type": "application/json;charset=utf-8",
      "OPEN-HEAD-KEY": "f372ec2c-aa0e-4caa-a74c-691da1272655",
      VueType: "vue"
    };
  }
  // if (modifyId && token) {
  //   headers = {
  //     "Content-Type": "application/json;charset=utf-8",
  //     "OPEN-HEAD-KEY": "f372ec2c-aa0e-4caa-a74c-691da1272655",
  //     VueType: "vue"
  //   };
  // }
  return headers;
}
const instance = axios.create({
  
  // baseURL: "http://123.56.112.114:8082/",
  baseURL: "https://admin.rdfapai.com/",

  timeout: 10000
});
instance.interceptors.request.use(
  config => {
    config.headers = getHeaders(); // 让每个请求携带自定义token 请根据实际情况自行修改

    return config;
  },
  error => {
    // Do something with request error
    console.log("request拦截器 出错：" + error); // for debug
    Promise.reject(error);
  }
);
// 响应拦截器
instance.interceptors.response.use(
  res => {
    // 对响应数据做点什么
    return res;
  },
  error => {
    if (error.response.data.status === 400) {
      sessionStorage.removeItem("userId");
    }
    // 对响应错误做点什么
    return Promise.reject(error);
  }
);
export default {
  // 获取验证码
  getVerifyCode(data) {
    return instance.get(`/customer/getVerifyCode?telephone=${data.id}`);
  },
  //登录接口
  fastLogin(data) {
    return instance.post("/customer/fastLogin", data);
  },
  // 首页搜索
  search(data) {
    return instance.post("/houseView/searchByTitle", data);
  },
  // 区域
  getListByPid(data) {
    return instance.get(`/area/getListByPid?pid=${data.id}`);
  },
  // 全部房源
  getHouseList(data) {
    return instance.post("/houseView/getHouseList", data);
  },
  // 房产详情
  getHouseDetail(data) {
    return instance.get(`/houseView/getHouseDetail/${data.id}`);
  },
  //本周上新
  NewHouse(data) {
    return instance.post("/houseView/getNewHouseOfWeek", data);
  },
  // 本周开拍
  SellHouse(data) {
    return instance.post("/houseView/getStartSellHouseOfWeek", data);
  },
  //本周特惠
  CheapHouse(data) {
    return instance.post("/houseView/getNewHouseOfWeek", data);
  },
  // 自由购
  FreedomBuy(data) {
    return instance.post("/houseView/getFreedomBuyHouseList", data);
  },
  //刚需捡漏
  CheapbyHouse(data) {
    //     return instance.post("/houseView/getCheapHouseList", data);
    return instance.post("/houseView/getNewHouseOfWeek", data);
  },
  // 贷款接口 /customer/personalLoan
  personalLoan(data) {
    return instance.post("/customer/personalLoan", data);
  },
  //申请贷款接口 customer/applyLoan
  applyLoan(data) {
    return instance.post("/customer/applyLoan", data);
  },
  // 个人信息接口 /customer/getPersonalInfo
  getPersonalInfo(data) {
    return instance.get(`/customer/getPersonalInfo?userId=${data.id}`);
  },
  // 个人信息接口 /customer/modifyPersonalInfo
  modifyPersonalInfo(data) {
    return instance.post("/customer/modifyPersonalInfo", data);
  },
  // 帮我找房接口  /customer/seachHouse
  seachHouse(data) {
    return instance.post("/customer/seachHouse", data);
  },
  // 精品房源
  HouseList(data) {
    return instance.post("/houseView/getWellHouseList", data);
  },
  // 取消关注
  cancelHouseFollow(data) {
    return instance.get(`/houseView/cancelHouseFollow/${data.id}`);
  },
  // 关注
  addHouseFollow(data) {
    return instance.post("/houseView/addHouseFollow", data);
  },
  // 上传图片
  openUpload(data) {
    return instance.post("/upload/openUpload", data);
  },
  // 退出登录
  fastLogout(data) {
    return instance.post("/customer/fastLogout", data);
  },
  //我的足迹
  getList(data) {
    return instance.post("/houseBrowse/getList", data);
  },
  // 我的关注
  houseFollow(data) {
    return instance.post("/houseFollow/getList", data);
  },
  // 设置提醒
  addRemind(data) {
    return instance.get(`/houseView/addRemind?id=${data.id}`);
  },
  // 留言
  add(data) {
    return instance.post("/customerMessage/add", data);
  },
  //全北京省
  StatisticsData(data) {
    return instance.get("/houseView/getHouseStatisticsData");
  },
  // 区域
  ByCountyId(data) {
    return instance.get(
      `/houseView/getHouseStatisticsDataByCountyId?countyId=${data.id}`
    );
  },
  //商业圈
  BusinessAreaId(data) {
    return instance.get(
      `/houseView/getHouseStatisticsDataByBusinessAreaId?businessAreaId=${data.id}`
    );
  },
  //免费订阅
  Subscribe(data) {
    return instance.post("/customerSubscribe/add", data);
  },
  // 经纪人详情
  fpManagerDetail(data) {
    return instance.get(`/manager/fpManagerDetail?managerId=${data.id}`);
  },
  // 房源
  getRemindHouseList(data) {
    return instance.post("/houseRemind/getRemindHouseList", data);
  },
  // 我的订阅
  mySubscribe(data) {
    return instance.get(
      `/customerSubscribe/mySubscribe?telephone=${data.telephone}&page=${data.page}&limit=${data.limit}`
    );
  },
  // 预约
  addAppointmentHouse(data) {
    return instance.post("/houseView/addAppointmentHouse", data);
  },
  // 足迹
  cancelHouseBrowse(data) {
    return instance.post("/houseView/cancelHouseBrowse", data);
  }
};
